package main;

import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;

public class DevilRun extends MIDlet {

    MainCanvas g;
    public boolean gamestart;

    public void startMainApp() {
        System.out.println("  start app ");
        try {
            System.out.println("   !!!!!!!!!!!!!!!!  ");
            if (!gamestart) {
                try{
                g = new MainCanvas(this);
                }catch(Exception e){
                    System.out.println("Error");
                }
//          System.out.println("Size: "+g.getWidth()+"x"+g.getHeight());
                Display.getDisplay(this).setCurrent(g);
                Thread myThread = new Thread(g);
                myThread.start();
                gamestart = true;
            } else {
                if (g.GameScreen == MainCanvas.GamePause) {
                    g.GameScreen = MainCanvas.GamePause;
                }
                if (g.GameScreen == MainCanvas.GamePlay) {
                    g.GameScreen = MainCanvas.GamePause;
                }
                if (g.GameScreen == MainCanvas.GameOver) {
                    g.GameScreen = MainCanvas.GameOver;
                }
            }
        } catch (Exception e) {
            System.out.println("Exception: " + e.toString());
        }
    }

    public void pauseMainApp() {
        try {
            g.mp3player[0].stop();
            if (g.GameScreen == MainCanvas.GamePlay) {
                g.GameScreen = MainCanvas.GamePause;
            }
            if (g.GameScreen == MainCanvas.GamePause) {
                g.GameScreen = MainCanvas.GamePause;
            }
            if (g.GameScreen == MainCanvas.GameOver) {
                g.GameScreen = MainCanvas.GameOver;
            }
        } catch (Exception e) {
        }
    }

    public void destroyMainApp(boolean unconditional) {
        try {
            g.mp3player[0].stop();
        } catch (Exception e) {
        }
    }

    public void pauseApp() {
        pauseMainApp();
    }

    public void destroyApp(boolean args0) {
        notifyDestroyed();
        destroyMainApp(args0);
    }

    public void constructorMainApp() {
        g = null;
    }

    protected void startApp() {
        startMainApp();
    }
}